const axios = require('axios');
let fs = require('fs');
axios.defaults.withCredentials = true;
let time = new Date().getTime() + 86400000;
console.log(time);
async function main() {
  // let fd = fs.openSync('book.html', 'w')

  //第一页
  let res = await axios({
    method:'post',
    url:`https://libsouthic.jnu.edu.cn/ic/index.curdateindex/${time}?id=3`,
    headers: {
      "x-requested-with" : 'XMLHttpRequest'
    }
  })
  res = res.data;
  // console.log(res);

  //改变状态网站
  let BaseUrl = 'https://libsouthic.jnu.edu.cn';
  let change = BaseUrl + res.inits[0].linkZone[0].url;
  console.log(change);

  //改变状态
  try {
    let page2Change = await axios({
      method:'post',
      url:change,
      headers: {
        "x-requested-with" : 'XMLHttpRequest'
      }
    })
    console.log('切换成功');
    console.log(page2Change.data);
  } catch (error) {
    console.log('切换失败');
  }
  

  //第二页
  let page2Res = await axios({
    method:'post',
    url:`https://libsouthic.jnu.edu.cn/ic/index.curdateindex/${time}?id=3`,
    headers: {
      "x-requested-with" : 'XMLHttpRequest'
    }
  })
  page2Res = page2Res.data;
  console.log(page2Res);

  // console.log(res);
  // fs.writeFileSync(fd, res.data);
  // fs.closeSync(fd);
  
}

main(); 
// console.log(1617465992388+86400000);
